//
//  MBForumBaseViewController.m
//  MiBaoTu
//
//  Created by admin on 16/10/14.
//  Copyright © 2016年 com.caesartech15. All rights reserved.
//

#import "MBForumBaseViewController.h"
#import "MBForumDetailViewController.h"
#import "MBLoginController.h"

#import "MBForumMainCell.h"
#import "ShowPictureView.h"
#import "AttentionView.h"

@interface MBForumBaseViewController ()<UITableViewDataSource,UITableViewDelegate,MBForumMainCellDelegate,AttentionViewDelegate,UIScrollViewDelegate> {
    UITableView                     *_tableView;
    UILabel                         *_showNoDataLb;  //无数据显示
    NSMutableArray                  *_cellHeightArr; //保存每个cell的高度
    NSMutableArray                  *_mutArr;
    NSInteger                        page;
    MBForumType                     selectType;
    
    NSMutableArray                  *_praiseArr; //保存点赞数据
    float                           nHeight;
}

@end
@implementation MBForumBaseViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    _cellHeightArr = [[NSMutableArray alloc]init];
    _praiseArr = [[NSMutableArray alloc]init];
    _mutArr = [[NSMutableArray alloc]init];
    page = 1;
    selectType = MBForumType_News;
    
    [self onCreateUI];
    [self loadDB];
    [self onLoadNew];
    
//    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(onChangePariseObjectAction:) name:@"LUNTAN_PARICE_CHANGE_NOTY" object:nil];
}

#pragma mark - UI
- (void)onCreateUI
{
    _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-NAV_HEIGHT-(ISIPAD?500*PERCEN:300*PERCEN)-80*PERCEN-50) style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _tableView.backgroundColor = [UIColor clearColor];
    _tableView.backgroundView = nil;
    [self.view addSubview:_tableView];
    [_tableView addLegendHeaderWithRefreshingTarget:self refreshingAction:@selector(onLoadNew)];
    [_tableView addLegendFooterWithRefreshingTarget:self refreshingAction:@selector(onLoadMore)];
    if (nHeight > 0) {
        [self onUPdateUIForTable:nHeight];
    }
    
    //暂无搜索结果
    _showNoDataLb = [[UILabel alloc]initWithFrame:CGRectMake(0, (_tableView.height-40)/2., _tableView.width, 40)];
    _showNoDataLb.backgroundColor = [UIColor clearColor];
    _showNoDataLb.text = @"暂无搜索结果";
    _showNoDataLb.textAlignment = NSTextAlignmentCenter;
    _showNoDataLb.textColor = UIColorFromHex(0x999999);
    _showNoDataLb.font = [UIFont systemFontOfSize:13.f];
    _showNoDataLb.hidden = YES;
    [self.view addSubview:_showNoDataLb];

}

#pragma mark - 加载数据
- (void)loadDB
{

}

- (void)onUPdateUIForTable:(float)height
{
    nHeight = height;
    _tableView.height = nHeight;
    [_tableView reloadData];
}

- (void)onLoadNew
{
    page = 1;
    [self loadData];
}

- (void)onLoadMore
{
    ++page;
    [self loadData];
}

- (void)loadData
{
    
    //1：最新，2：热门，3：活动
    int index = 1;
    if (_type == MBForumType_News) {
        index = 1;
    }
    else if (_type == MBForumType_Hots) {
        index = 2;
    }
    else if (_type == MBForumType_Activitys) {
        index = 3;
    }
    UserModel *model = [UserManager standerDefult].userModel;
    [[HTTPManager standerDefault]AFGetRequest:[NSString stringWithFormat:FORUM_ACTIVITY_LIST_URL_PATH,[NSNumber numberWithInteger:page],[NSNumber numberWithInt:index],(model?model.UserID:@"")] view:nil success:^(NSDictionary *json) {
        [_tableView.header endRefreshing];
        [_tableView.footer endRefreshing];
        
        if ([json isKindOfClass:[NSDictionary class]]) {
            if ([json[@"ret_code"] integerValue]==0) {
                NSArray *arr = json[@"data"];
                
                if (_type == selectType) {
                    if (page == 1) {
                        [_mutArr removeAllObjects];
                        [_cellHeightArr removeAllObjects];
                    }
                } else {
                     [_mutArr removeAllObjects];
                    [_cellHeightArr removeAllObjects];
                }
                [_mutArr addObjectsFromArray:arr];
                
                if (_type == MBForumType_Activitys) {
                    //活动格式例外
                    for (int i=0; i<arr.count; i++) {
                        float allHeight = 0;
                        NSDictionary *dic = arr[i];
                        NSMutableString *content = [NSMutableString stringWithString:[dic objectForKey:@"Content"]];
                        NSMutableString *contMutStr = [[NSMutableString alloc]init];
                        NSMutableArray  *imgContentArr = [[NSMutableArray alloc]init];
                        
                        [content replaceOccurrencesOfString:@"<p>" withString:@"" options:1 range:NSMakeRange(0, content.length)];
                        [content replaceOccurrencesOfString:@"</p>" withString:@"\n" options:1 range:NSMakeRange(0, content.length)];
                        [content replaceOccurrencesOfString:@"<br/>" withString:@"\n" options:1 range:NSMakeRange(0, content.length)];
                        NSArray *contentArr = [content componentsSeparatedByString:@"<img src="];
                        for (NSString *picStr in contentArr) {
                            if ([picStr containsString:@" title="]) {
                                //纯图片
                                NSArray *picUrlArr = [picStr componentsSeparatedByString:@" title="];
                                NSMutableString *picUrlStr = [NSMutableString stringWithString:picUrlArr[0]];
                                if (picUrlStr.length > 0) {
                                    [picUrlStr replaceOccurrencesOfString:@"\"" withString:@"" options:1 range:NSMakeRange(0, picUrlStr.length)];
                                    [imgContentArr addObject:picUrlStr];
                                }
                                if ([picUrlStr containsString:@"\"/>"]) {
                                    NSArray *picContentArr = [picUrlStr componentsSeparatedByString:@"\"/>"];
                                    [contMutStr appendString:picContentArr[1]];
                                }
                            } else {
                                [contMutStr appendString:picStr];
                            }
                        }
                        NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc]init];
                        paragraph.lineSpacing = 10*PERCEN;
                        NSMutableAttributedString *mutStr = [[NSMutableAttributedString alloc]initWithString:contMutStr];
                        [mutStr addAttribute:NSParagraphStyleAttributeName value:paragraph range:NSMakeRange(0, contMutStr.length)];
                        
                        if (ISIPAD) {
                            [mutStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:28*PERCEN] range:NSMakeRange(0, contMutStr.length)];
                        }else{
                            
                            [mutStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:13.f] range:NSMakeRange(0, contMutStr.length)];
                        }

                        float contentHeight =[mutStr boundingRectWithSize:CGSizeMake((SCREEN_WIDTH-50*PERCEN), 20000) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading context:NULL].size.height;
                        allHeight = 120*PERCEN+(20+10*PERCEN+(contentHeight < 110*PERCEN?contentHeight:110*PERCEN))+(imgContentArr.count == 0 ?0:(20*PERCEN+220*PERCEN))+(20*PERCEN+40*PERCEN+20*PERCEN)+20*PERCEN;
                        
                        if (ISIPAD) {
                            contentHeight =[mutStr boundingRectWithSize:CGSizeMake((SCREEN_WIDTH-2*470*PERCEN), 20000) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading context:NULL].size.height;
                            
                            allHeight = 140*PERCEN+(30*PERCEN+52*PERCEN+(contentHeight < 110*PERCEN?contentHeight:110*PERCEN))+(imgContentArr.count == 0 ?0:(30*PERCEN+352*PERCEN))+(30*PERCEN+40*PERCEN+45*PERCEN)+30*PERCEN;
                       
                        }

                     
                   
            
                        [_cellHeightArr addObject:[NSNumber numberWithFloat:allHeight]];
                    }
                    
                } else {
                    //记录cell的高度
                    for (int i=0; i<arr.count; i++) {
                        float allHeight = 0;
                        NSDictionary *dic = arr[i];
                        NSString *content = [dic objectForKey:@"Content"];
                        //                    NSString *content = @"今天和Emily一起去海洋馆玩了，很累，不过很开心！非常值得，期待下次的亲子游记。今天和Emily一起去海洋馆玩了，很累，不过很开心！非常值得，期待下次的亲子游记。今天和Emily一起去海洋馆玩了，很累，不过很开心！非常值得，期待下次的亲子游记。今天和Emily一起去海洋馆玩了，很累，不过很开心！非常值得，期待下次的亲子游记。";
                        
                        NSArray *contentArr = [content componentsSeparatedByString:@"\n"];
                        NSMutableString *contMutStr = [[NSMutableString alloc]init];
                        NSMutableArray  *imgContentArr = [[NSMutableArray alloc]init];
                        if (contentArr.count == 1) {
                            contentArr = [content componentsSeparatedByString:@"<img"];
                            for (NSString *showContent in contentArr) {
                                if (![showContent containsString:@"width=\"100%\">"]) {
                                    NSArray *ntextAllArr = [showContent componentsSeparatedByString:@"width=\"100%\">"];
                                    for (NSString *tt in ntextAllArr) {
                                        if ([tt rangeOfString:@".png"].location != NSNotFound ||
                                            [tt rangeOfString:@".PNG"].location != NSNotFound ||
                                            [tt rangeOfString:@".jpg"].location != NSNotFound ||
                                            [tt rangeOfString:@".JPG"].location != NSNotFound ||
                                            [tt rangeOfString:@".jpeg"].location != NSNotFound ||
                                            [tt rangeOfString:@".JPEG"].location != NSNotFound) {
                                            //该结为图片
                                            NSMutableString *imgStr = [NSMutableString stringWithFormat:@"%@",tt];
                                            [imgStr replaceOccurrencesOfString:@" '/" withString:@"" options:1 range:NSMakeRange(0, imgStr.length)];
                                            [imgStr replaceOccurrencesOfString:@"'/ " withString:@"" options:1 range:NSMakeRange(0, imgStr.length)];
                                            [imgStr insertString:[NSString stringWithFormat:@"%@/",MUSIC_PLAY_Url] atIndex:0];
                                            [imgContentArr addObject:imgStr];
                                        } else {
                                            [contMutStr appendString:tt];
                                        }
                                    }
                                } else {
                                    NSArray *nArr = [showContent componentsSeparatedByString:@"width=\"100%\">"];
                                    [contMutStr appendString:[nArr lastObject]];
                                    
                                    //添加图片
                                    if ([nArr[0] hasPrefix:@" src = "]) {
                                        NSMutableString *imgStr = [NSMutableString stringWithFormat:@"%@",nArr[0]];
                                        [imgStr replaceOccurrencesOfString:@" src = " withString:@"" options:1 range:NSMakeRange(0, imgStr.length)];
                                        [imgStr replaceOccurrencesOfString:@"'/" withString:@"" options:1 range:NSMakeRange(0, imgStr.length)];
                                        [imgStr replaceOccurrencesOfString:@"png " withString:@"png" options:1 range:NSMakeRange(0, imgStr.length)];
                                        [imgStr insertString:[NSString stringWithFormat:@"%@/",MUSIC_PLAY_Url] atIndex:0];
                                        [imgContentArr addObject:imgStr];
                                    }
                                }
                            }
                        }
                        else {
                            for (NSString *showContent in contentArr) {
                                if (![showContent hasPrefix:@"<img"]) {
                                    if ([showContent rangeOfString:@"<img src ="].location != NSNotFound) {
                                        //这段蚊子中包含图片地址，拆解吧 愤怒的少年
                                        NSArray *contentAllArr = [showContent componentsSeparatedByString:@"<img src ="];
                                        for (NSString *ntext in contentAllArr) {
                                            if ([ntext rangeOfString:@"width=\"100%\">"].location != NSNotFound) {
                                                //查看这节是否是图片地址部分
                                                NSArray *ntextAllArr = [ntext componentsSeparatedByString:@"width=\"100%\">"];
                                                for (NSString *tt in ntextAllArr) {
                                                    if ([tt rangeOfString:@".png"].location != NSNotFound ||
                                                        [tt rangeOfString:@".PNG"].location != NSNotFound ||
                                                        [tt rangeOfString:@".jpg"].location != NSNotFound ||
                                                        [tt rangeOfString:@".JPG"].location != NSNotFound ||
                                                        [tt rangeOfString:@".jpeg"].location != NSNotFound ||
                                                        [tt rangeOfString:@".JPEG"].location != NSNotFound) {
                                                        //该结为图片
                                                        NSMutableString *imgStr = [NSMutableString stringWithFormat:@"%@",tt];
                                                        [imgStr replaceOccurrencesOfString:@"'/" withString:@"" options:1 range:NSMakeRange(0, imgStr.length)];
                                                        [imgStr replaceOccurrencesOfString:@"'/ " withString:@"" options:1 range:NSMakeRange(0, imgStr.length)];
                                                        [imgStr insertString:[NSString stringWithFormat:@"%@/",MUSIC_PLAY_Url] atIndex:0];
                                                        [imgContentArr addObject:imgStr];
                                                    } else {
                                                        [contMutStr appendString:tt];
                                                    }
                                                }
                                            } else {
                                                [contMutStr appendString:ntext];
                                            }
                                        }
                                    } else {
                                        [contMutStr appendString:showContent];
                                    }
                                } else {
                                    //添加图片
                                    NSMutableString *imgStr = [NSMutableString stringWithFormat:@"%@",showContent];
                                    [imgStr replaceOccurrencesOfString:@"<img src = " withString:@"" options:1 range:NSMakeRange(0, imgStr.length)];
                                    [imgStr replaceOccurrencesOfString:@"'/" withString:@"" options:1 range:NSMakeRange(0, imgStr.length)];
                                    [imgStr replaceOccurrencesOfString:@" width=\"100%\">" withString:@"" options:1 range:NSMakeRange(0, imgStr.length)];
                                    [imgStr insertString:[NSString stringWithFormat:@"%@/",MUSIC_PLAY_Url] atIndex:0];
                                    [imgContentArr addObject:imgStr];
                                }
                            }
                        }
                        
                        NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc]init];
                        paragraph.lineSpacing = 10*PERCEN;
                        NSMutableAttributedString *mutStr = [[NSMutableAttributedString alloc]initWithString:contMutStr];
                        [mutStr addAttribute:NSParagraphStyleAttributeName value:paragraph range:NSMakeRange(0, contMutStr.length)];
                        
                        if (ISIPAD) {
                            [mutStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:28*PERCEN] range:NSMakeRange(0, contMutStr.length)];
                        }else{
                            
                            [mutStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:13.f] range:NSMakeRange(0, contMutStr.length)];
                        }
                     
                        float contentHeight =[mutStr boundingRectWithSize:CGSizeMake((SCREEN_WIDTH-50*PERCEN), 20000) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading context:NULL].size.height;
                        allHeight = 120*PERCEN+(20+10*PERCEN+(contentHeight < 110*PERCEN?contentHeight:110*PERCEN))+(imgContentArr.count == 0 ?0:(10*PERCEN+220*PERCEN))+(20*PERCEN+40*PERCEN+20*PERCEN)+20*PERCEN;
                        
                        if (ISIPAD) {
                            contentHeight =[mutStr boundingRectWithSize:CGSizeMake((SCREEN_WIDTH-2*470*PERCEN), 20000) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading context:NULL].size.height;
                            
                            allHeight = 140*PERCEN+(30*PERCEN+52*PERCEN+(contentHeight < 110*PERCEN?contentHeight:110*PERCEN))+(imgContentArr.count == 0 ?0:(30*PERCEN+352*PERCEN))+(30*PERCEN+40*PERCEN+45*PERCEN)+30*PERCEN;
                           
                        }
                        NSString*EliteStatus=[NSString stringWithFormat:@"%@",dic[@"EliteStatus"]]   ;
                        NSString*TopStatus= [NSString stringWithFormat:@"%@",dic[@"TopStatus"]];
                        
                        
                        if (_type==0) {
                            if ([EliteStatus isEqualToString:@"0"]&&[TopStatus isEqualToString:@"0"]) {
                                
                                
                                [_cellHeightArr addObject:[NSNumber numberWithFloat:allHeight]];
                            }else{
                                if (ISIPAD) {
                                    [_cellHeightArr addObject:[NSNumber numberWithFloat:252*PERCEN]];
                                }else{
                                    [_cellHeightArr addObject:[NSNumber numberWithFloat:210*PERCEN]];
                                }
                            }
                            

                        }else{
                            [_cellHeightArr addObject:[NSNumber numberWithFloat:allHeight]];
                        }
                        
                        
                        
                       
                    }
                }
                
                
                selectType = _type;
                [_tableView reloadData];
            }
        }
    } failure:^(NSError *error) {
        [_tableView.header endRefreshing];
        [_tableView.footer endRefreshing];
    }];
}

- (void)onChangePariseObjectAction:(NSDictionary *)dic withIndex:(int)index
{
    if ([dic isKindOfClass:[NSDictionary class]]) {

        NSString *isParise = [dic objectForKey:@"isParise"];

        if (_mutArr.count <= index || index < 0) return;
        NSDictionary *value = [_mutArr objectAtIndex:index];
        NSMutableDictionary *mutDic = [[NSMutableDictionary alloc]initWithDictionary:value];
        if ([isParise boolValue] == 1) {
            //数据更新
            if (index < _mutArr.count && index >= 0) {
                [mutDic setValue:[NSNumber numberWithInt:([[value objectForKey:@"PraiseNum"] intValue]+1)] forKey:@"PraiseNum"];
                [mutDic setValue:[NSString stringWithFormat:@"%@",isParise] forKey:@"PraiseStatus"];
                [_mutArr replaceObjectAtIndex:index withObject:mutDic];
                [_tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForItem:index inSection:0]] withRowAnimation:UITableViewRowAnimationFade];
            }
        } else {
            //数据更新
            if (index < _mutArr.count && index >= 0) {
                [mutDic setValue:[NSNumber numberWithInt:([[value objectForKey:@"PraiseNum"] intValue]-1)] forKey:@"PraiseNum"];
                [mutDic setValue:[NSString stringWithFormat:@"%@",isParise] forKey:@"PraiseStatus"];
                [_mutArr replaceObjectAtIndex:index withObject:mutDic];
                [_tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForItem:index inSection:0]] withRowAnimation:UITableViewRowAnimationFade];
            }
        }
        [_tableView reloadData];
    }
}

#pragma mark - 删除、查看图片、点赞
//删除
- (void)onSelectItemForDeleteByForumCellWithView:(MBForumMainCell *)view withValue:(NSDictionary *)value {
    
    if ([value isKindOfClass:[NSDictionary class]]) {
        
        AttentionView *_attention = [[AttentionView alloc]initWithTitle:[NSString stringWithFormat:@"是否确认删除话题《%@》?",[value objectForKey:@"Title"]] withCancelBt:@"确认" withSureBt:@"取消"];
        _attention.delegate = self;
        _attention.orientation = self.orientation;
        _attention.dataDic = value;
        [_attention showInWindow];
    }
    
}

- (void)onSelectSureItem:(AttentionView *)view
{
}
- (void)onSelectCancelItem:(AttentionView *)view
{
    //删除
    UserModel *model = [UserManager standerDefult].userModel;
    if (!model.UserID) {
        MBLoginController *registerLastVC = [[MBLoginController alloc] init];
        registerLastVC.formBaseViewCtrl = NSStringFromClass([self class]);
        [self.navigationController pushViewController:registerLastVC animated:YES];
        return;
    }
    
    NSDictionary *dic = view.dataDic;
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    if (dic.allKeys.count > 0) {
        [[HTTPManager standerDefault]AFGetRequest:[NSString stringWithFormat:FORUM_DELETE_URL_PATH,[dic objectForKey:@"ID"],model.UserID] view:nil success:^(id json) {
            [MBProgressHUD hideHUDForView:self.view animated:YES];
            if ([json[@"ret_code"] integerValue]==0) {
                if ([_mutArr containsObject:dic]) {
                    int index = (int)[_mutArr indexOfObject:dic];
                    [_mutArr removeObject:dic];
                    [_cellHeightArr removeObjectAtIndex:index];
                    [_tableView deleteRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:index inSection:0]] withRowAnimation:UITableViewRowAnimationFade];
                }
            }else {
                [ErrorMessage showErrorMessage:json[@"message"] inView:self.view];
            }
        } failure:^(NSError *error) {
            [MBProgressHUD hideHUDForView:self.view animated:YES];
        }];
    }
}

//查看图片
- (void)onSelectItemForSeePictureByForumCellWithView:(MBForumMainCell *)view withValue:(NSArray *)value withNum:(NSInteger)num{
//    NSArray *ss =@[@"http://mbt.hzxgroup.com/upload/2016-10-9/1.png",@"http://cc.cocimg.com/bbs/3g/img/ccicon.png",@"http://mbt.hzxgroup.com/upload/2016-10-9/1.png",@"http://cc.cocimg.com/bbs/3g/img/ccicon.png",@"http://mbt.hzxgroup.com/upload/2016-10-9/1.png"];
 
    if ([value isKindOfClass:[NSArray class]]) {
        NSMutableArray *mutArr = [[NSMutableArray alloc]init];
        for (NSString *urlStr in value) {
            if (![urlStr hasPrefix:[NSString stringWithFormat:@"%@/'",MUSIC_PLAY_Url]]) {
                [mutArr addObject:urlStr];
            }
        }
        
        ShowPictureView *show = [[ShowPictureView alloc]initWithDataArr:mutArr withMark:num];
        show.orientation = self.orientation;
     
        [show onShowInWindow];
    }
}
//点赞
- (void)onSelectItemForZanByForumCellWithView:(MBForumMainCell *)view withValue:(NSDictionary *)value
{
    return;
}

#pragma mark - UITableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
   return _mutArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellID = @"Forum_Music_Cell";
    MBForumMainCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (!cell) {
        cell = [[MBForumMainCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        cell.delegate = self;
    }
    
    if (_mutArr.count > indexPath.row) {
        NSDictionary *dic = [_mutArr objectAtIndex:indexPath.row];
        cell.isParise = NO;//[[dic objectForKey:@"PraiseStatus"]boolValue];
        
        cell.dataDic = dic;
        
    }
    
    cell.isActivity = (_type == MBForumType_Activitys ? YES : NO);
    cell.isNew=(_type==MBForumType_News ?YES:NO);
    return cell;

}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (_cellHeightArr.count > indexPath.row) {
        return [[_cellHeightArr objectAtIndex:indexPath.row] floatValue];
    }
    return 0;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (_mutArr.count > indexPath.row) {
        MBForumDetailViewController *detail = [[MBForumDetailViewController alloc]init];
        detail.dataDic = [_mutArr objectAtIndex:indexPath.row];
        detail.isActivity = (_type == MBForumType_Activitys ? YES : NO);
        
        NSDictionary *dic = [_mutArr objectAtIndex:indexPath.row];
        detail.isParise = [[dic objectForKey:@"PraiseStatus"]boolValue];
        detail.finishBlock = ^ (NSString *type,NSDictionary *dateDic) {

            if ([type isEqualToString:@"ViewNum"]) {
                if (![_mutArr containsObject:dateDic]) return ;
                
                int index = (int)[_mutArr indexOfObject:dateDic];
                
                //查看数据
                int ViewNum = [[dateDic objectForKey:@"ViewNum"]intValue];
                NSMutableDictionary *nMutDic = [[NSMutableDictionary alloc]initWithDictionary:dateDic];
                [nMutDic setValue:[NSString stringWithFormat:@"%d",ViewNum+1] forKey:@"ViewNum"];
                [_mutArr replaceObjectAtIndex:index withObject:nMutDic];
                [_tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForItem:index inSection:0]] withRowAnimation:UITableViewRowAnimationFade];
            }
            else if ([type isEqualToString:@"cancel_zan"]) {
                //取消点赞
                [self onChangePariseObjectAction:dateDic withIndex:(int)indexPath.row];
            }
            else if ([type isEqualToString:@"zan"]) {
                //点赞
                [self onChangePariseObjectAction:dateDic withIndex:(int)indexPath.row];
            }
            else if ([type isEqualToString:@"deleteForum"]) {
                //删除帖子
                NSMutableArray *tieziIDArr = [[NSMutableArray alloc]initWithCapacity:_mutArr.count];
                for (NSDictionary *dic in _mutArr) {
                    [tieziIDArr addObject:[NSString stringWithFormat:@"%@",[dic objectForKey:@"ID"]]];
                }
                BOOL isExit = NO;
                NSString *idString = [NSString stringWithFormat:@"%@",[dateDic objectForKey:@"ID"]];
                for (NSString *str in tieziIDArr) {
                    if ([idString isEqualToString:str]) {
                        isExit = YES;
                    }
                }
                if (isExit == NO) return ;
                int index = (int)[tieziIDArr indexOfObject:idString];
                [_mutArr removeObjectAtIndex:index];
                [_cellHeightArr removeObjectAtIndex:index];
                [_tableView deleteRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:index inSection:0]] withRowAnimation:UITableViewRowAnimationFade];

            }
        };
        [self.navigationController pushViewController:detail animated:YES];
    }
}

#pragma mark - ScrollView Delegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    float y = scrollView.contentOffset.y;
//    NSLog(@"滑动位移:%.2f",y);
    if (y > 0 && y < (ISIPAD?500*PERCEN:300*PERCEN)*2) {
        //隐藏
        if (self.onShowUIForBlock) {
            if (y >= (ISIPAD?500*PERCEN:300*PERCEN)) y = (ISIPAD?500*PERCEN:300*PERCEN);
            self.onShowUIForBlock(y);
             NSLog(@"隐藏位移:%.2f",y);
        }
    }
    else if ((y < 0 && y > -(ISIPAD?500*PERCEN:300*PERCEN))) {
        //显示
        if (self.onShowUIForBlock) {
            if (y <= 0) y = 0;
            self.onShowUIForBlock(y);
//             NSLog(@"****显示位移:%.2f",y);
        }
    }
}

@end
